package com.systop.controller;

import com.systop.pojo.Goods_property;
import com.systop.service.GoodsPropertyService;
import com.systop.unti.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author zhangnan
 * @Data 2020/8/004 下午 4:24
 * @Descriiption
 **/
@RestController
@RequestMapping("/GoodsProperty")
public class GoodsPropertyController {
    @Autowired
    private GoodsPropertyService goodsPropertyService;
    //分页查询

    //查所有
    @RequestMapping(value = "/selectAll", method = RequestMethod.POST)
    public ResponseResult selectAll(){
        ResponseResult responseResult = goodsPropertyService.selectGoodsPropertyAll();
        return responseResult;
    }
    //根据id查询
    @RequestMapping(value = "/selectgoodsPropertyByid", method = RequestMethod.POST)
    public ResponseResult selectgoodsPropertyByid(@RequestParam("goods_property_id") Integer goods_property_id){
        ResponseResult responseResult = goodsPropertyService.selectGoodsPropertByid(goods_property_id);
        return responseResult;
    }
    //根据名字查询
    @RequestMapping(value = "/selectgoodsPropertyByname", method = RequestMethod.POST)
    public ResponseResult selectgoodsPropertyByname(@RequestParam("goods_property_name") String goods_property_name){
        ResponseResult responseResult = goodsPropertyService.selectGoodsPropertByname(goods_property_name);
        return responseResult;
    }
    //根据id删除
    @RequestMapping(value = "/deletegoodsPropertyByid", method = RequestMethod.POST)
    public ResponseResult deletegoodsPropertyByid(@RequestParam("goods_property_id") Integer goods_property_id){
        ResponseResult responseResult = goodsPropertyService.deleteGoodsPropertByid(goods_property_id);
        return responseResult;
    }
    //添加商品属性
    @RequestMapping(value = "/insertgoodsProperty", method = RequestMethod.POST)
    public ResponseResult insertgoodsProperty(@RequestParam("goods_property_name") String goods_property_name){
        Goods_property goods_property = new Goods_property();
        goods_property.setGoods_property_name(goods_property_name);
//        System.out.println(goods_property);
        return goodsPropertyService.insertGoodsPropert(goods_property);
    }
    //更新商品属性
    @RequestMapping(value = "/updategoodsPropertyByid", method = RequestMethod.POST)
    public ResponseResult updategoodsPropertyByid(@RequestParam("goods_property_name") String goods_property_name,
                                                  @RequestParam("goods_property_id") Integer goods_property_id){
//        System.out.println(goods_property_name);
//        System.out.println(goods_property_id);
        Goods_property goods_property = new Goods_property();
//        System.out.println(goods_property);
        goods_property.setGoods_property_name(goods_property_name);
        goods_property.setGoods_property_id(goods_property_id);
        return goodsPropertyService.updateGoodsPropertByid(goods_property);

    }


}
